package org.xlp.auto.create.util;

import org.xlp.auto.create.AbstractAutoCreator;
import org.xlp.beancovert.BeanCovert;
import org.xlp.beancovert.BeanFieldConvertSettings;
import org.xlp.beancovert.exception.BeanConvertException;

/**
 * Description: 提供自动创建类相互转换功能
 * <br/>date: 2023/12/1 16:41
 *
 * @version 1.0
 * @author: xlp
 */
public class AutoCreatorUtils {
    /**
     * 转换设置
     */
    private static final BeanFieldConvertSettings CONVERT_SETTINGS = new BeanFieldConvertSettings();

    static {
        // 设置转换属性
        CONVERT_SETTINGS.setCovertFailThrow(false);
        CONVERT_SETTINGS.addIgnoreFieldName("supperClassName");
        CONVERT_SETTINGS.addIgnoreFieldName("interfaceNames");
        CONVERT_SETTINGS.addIgnoreFieldName("classType");
    }

    /**
     * 自动创建类相互转换，参数为空，不做任何操作
     * @param target 转换成的目标
     * @param source 被转换对象
     */
     public static void autoCreatorConvert(AbstractAutoCreator target, AbstractAutoCreator source){
         if (target == null || source == null) return;
         BeanCovert beanCovert = new BeanCovert(CONVERT_SETTINGS);
         beanCovert.setCovertFailThrow(false);
         try {
             beanCovert.covert(target, source);
         } catch (BeanConvertException ignored) {}
     }
}
